<?php

namespace app\liantang\service;

use think\admin\Service;
use think\Cache;

use WeMini\Newtmpl;

/**
 * 小程序接口服务
 * Class UserService
 * @package app\store\service
 */
class WxappService extends Service
{


    const VERIFY_TEMPLATE_ID = "f0TdGoY_Oxrdi0mU9OWioewpTJ3mFRMb4Hp0clkxqH0";
    /**
     * 小程序配置参数
     * @var array
     */
    protected $config;

    /**
     * 接口服务初始化
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function initialize()
    {
        $this->config = [
            'appid'      => sysconf('data.wxapp_appid'),
            'appsecret'  => sysconf('data.wxapp_appkey')
        ];
    } 
    

    /**
     * 发送审核模板消息(订阅消息)
     */
    
    public function sendVerifySubscribeMsg($openid,$content,$configs, $page="")
    {

        // 发送模板消息 通知
        $data = array(
            "template_id" => WxappService::instance()::VERIFY_TEMPLATE_ID,
            "touser" => $openid,
            "data" => $content
        );

        if (!empty($page)) {
            $data["page"] = $page;
        }

        $this->app->log->error('活动提醒模板消息参数:' . json_encode($data));

        Newtmpl::instance($configs)->send($data);

        return true;

    }
}